//
//  CitySourceTool.m
//  定制公交
//
//  Created by thinkjoy on 16/4/15.
//  Copyright © 2016年 thinkjoy. All rights reserved.
//

#import "CitySourceTool.h"

//城市的plist文件
#define RSDIVISION      @"Division"
#define RSDIVISIONNAME  @"DivisionName"
#define RSDIVISIONSUB   @"DivisionSub"

@implementation CitySourceTool

static NSArray *_cities;


+ (NSArray *)allProvinces
{
//    if (_cities == nil) {
        //通过plist文件取出一个大字典
        NSDictionary    * districtDic = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"districtMGE" ofType:@"plist"]];
        
        //从字典中取出省级列表数组
        NSArray * allAry    =   [districtDic objectForKey:RSDIVISION];
        NSString    * provinceStr   =   nil;
        NSMutableArray  *   provinceMuAry   =   [[NSMutableArray alloc]init];
        for (NSDictionary * dic in allAry) {
            provinceStr  =   [dic objectForKey:RSDIVISIONNAME];
            //        NSLog(@"====%@",provinceStr);
            [provinceMuAry   addObject:provinceStr];
        }
//        _cities = provinceMuAry;
//    }
    return provinceMuAry;
}

+ (NSArray *)allCitys
{
    NSDictionary    * allDic    =   [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"districtMGE" ofType:@"plist"]];
    NSArray * allAry    =   [allDic objectForKey:RSDIVISION];
    
    NSString    * cityStr       =   nil;
    
    NSMutableArray  * allCityMuAry  =   [NSMutableArray array]; //存放所有城市的数组,里面在分别存放每个省的城市
    for (NSDictionary * dic in allAry) {
        NSMutableArray  * cityMuAry      =   [NSMutableArray array];    //存放单独省份的城市
        NSArray     * cityAry   =   [dic objectForKey:RSDIVISIONSUB];  //每个省份存放的城市数组
        //        NSLog(@"+++%lu",(unsigned long)cityAry.count);
        for (NSDictionary * dic1 in cityAry) {
            
            cityStr =   [dic1 objectForKey:RSDIVISIONNAME];
            //            NSLog(@"cityStr====%@",cityStr);
            [cityMuAry   addObject:cityStr];
        }
        [allCityMuAry    addObject:cityMuAry];
        //        NSLog(@"allCityMuAry.count====%d",allCityMuAry.count);
    }
//    _cities    =   allCityMuAry;
    
    return allCityMuAry;
}
+ (NSArray *)allProvincesWithBusHallDistrictMGE
{
//    if (_cities == nil) {
//        //通过plist文件取出一个大字典
//        NSDictionary    * districtDic = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BusHallDistrictMGE" ofType:@"plist"]];
//        
//        //从字典中取出省级列表数组
//        NSArray * allAry    =   [districtDic objectForKey:RSDIVISION];
//        NSString    * provinceStr   =   nil;
//        NSMutableArray  *   provinceMuAry   =   [[NSMutableArray alloc]init];
//        for (NSDictionary * dic in allAry) {
//            provinceStr  =   [dic objectForKey:RSDIVISIONNAME];
//            //        NSLog(@"====%@",provinceStr);
//            [provinceMuAry   addObject:provinceStr];
//        }
//        _cities = provinceMuAry;
//    }
    NSDictionary    * allDic    =   [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BusHallDistrictMGE" ofType:@"plist"]];
    NSArray * allAry    =   [allDic objectForKey:RSDIVISION];
    
    NSString    * provinceStr   =   nil;
    NSString    * cityStr       =   nil;
    
    //    NSMutableArray  * cityMuAry  ; //存放单独省份的城市
    NSMutableArray  * provinceMuAry =   [NSMutableArray array]; //存放省份的数组
    
    NSMutableArray  * allCityMuAry  =   [NSMutableArray array]; //存放所有城市的数组,里面在分别存放每个省的城市
    for (NSDictionary * dic in allAry) {
        provinceStr  =   [dic objectForKey:RSDIVISIONNAME];
        //        NSLog(@"====%@",provinceStr);
        [provinceMuAry   addObject:provinceStr];
        
        NSMutableArray  * cityMuAry      =   [NSMutableArray array];    //存放单独省份的城市
        NSArray     * cityAry   =   [dic objectForKey:RSDIVISIONSUB];  //每个省份存放的城市数组
        //        NSLog(@"+++%lu",(unsigned long)cityAry.count);
        for (NSDictionary * dic1 in cityAry) {
            
            cityStr =   [dic1 objectForKey:RSDIVISIONNAME];
            //            NSLog(@"cityStr====%@",cityStr);
            [cityMuAry   addObject:cityStr];
        }
        [allCityMuAry    addObject:cityMuAry];
        //        NSLog(@"allCityMuAry.count====%d",allCityMuAry.count);
    }
    
//    self.allProvincesAry    =   provinceMuAry;
//    self.allCitysAry     =   allCityMuAry;

    return provinceMuAry;
}

+ (NSArray *)allCitysWithBusHallDistrictMGE
{
//    NSDictionary    * allDic    =   [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BusHallDistrictMGE" ofType:@"plist"]];
//    NSArray * allAry    =   [allDic objectForKey:RSDIVISION];
//    
//    NSString    * cityStr       =   nil;
//    
//    NSMutableArray  * allCityMuAry  =   [NSMutableArray array]; //存放所有城市的数组,里面在分别存放每个省的城市
//    for (NSDictionary * dic in allAry) {
//        NSMutableArray  * cityMuAry      =   [NSMutableArray array];    //存放单独省份的城市
//        NSArray     * cityAry   =   [dic objectForKey:RSDIVISIONSUB];  //每个省份存放的城市数组
//        //        NSLog(@"+++%lu",(unsigned long)cityAry.count);
//        for (NSDictionary * dic1 in cityAry) {
//            
//            cityStr =   [dic1 objectForKey:RSDIVISIONNAME];
//            //            NSLog(@"cityStr====%@",cityStr);
//            [cityMuAry   addObject:cityStr];
//        }
//        [allCityMuAry    addObject:cityMuAry];
//        //        NSLog(@"allCityMuAry.count====%d",allCityMuAry.count);
//    }
    NSDictionary    * allDic    =   [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BusHallDistrictMGE" ofType:@"plist"]];
    NSArray * allAry    =   [allDic objectForKey:RSDIVISION];
    
    NSString    * provinceStr   =   nil;
    NSString    * cityStr       =   nil;
    
    //    NSMutableArray  * cityMuAry  ; //存放单独省份的城市
    NSMutableArray  * provinceMuAry =   [NSMutableArray array]; //存放省份的数组
    
    NSMutableArray  * allCityMuAry  =   [NSMutableArray array]; //存放所有城市的数组,里面在分别存放每个省的城市
    for (NSDictionary * dic in allAry) {
        provinceStr  =   [dic objectForKey:RSDIVISIONNAME];
        //        NSLog(@"====%@",provinceStr);
        [provinceMuAry   addObject:provinceStr];
        
        NSMutableArray  * cityMuAry      =   [NSMutableArray array];    //存放单独省份的城市
        NSArray     * cityAry   =   [dic objectForKey:RSDIVISIONSUB];  //每个省份存放的城市数组
        //        NSLog(@"+++%lu",(unsigned long)cityAry.count);
        for (NSDictionary * dic1 in cityAry) {
            
            cityStr =   [dic1 objectForKey:RSDIVISIONNAME];
            //            NSLog(@"cityStr====%@",cityStr);
            [cityMuAry   addObject:cityStr];
        }
        [allCityMuAry    addObject:cityMuAry];
        //        NSLog(@"allCityMuAry.count====%d",allCityMuAry.count);
    }
    
//    self.allProvincesAry    =   provinceMuAry;
//    self.allCitysAry     =   allCityMuAry;

//    _cities    =   allCityMuAry;
    
    return allCityMuAry;
}
@end
